#include <bits/stdc++.h>
using namespace std;
int f[3005][3005];
int main() {
  string s1, s2;
  cin >> s1 >> s2;
  int ans = 0, len1 = s1.size(), len2 = s2.size();
  s1 = ' ' + s1;
  s2 = ' ' + s2;
  f[0][0] = 1;
  for (int i = 1; i <= len1; i++)
    for (int j = 0; j <= len2; j++) {
      if (s1[i] == '?' || s1[i] == s2[j]) {
        f[i][j] = f[i - 1][j - 1];
      } else if (s1[i] == '*') {
        int bj = 0;
        for (int k = j; k >= 0; k--)
          if (f[i - 1][k]) {
            bj = 1; 
            break;
          }
        if (bj)
          f[i][j] = 1;
      }
    }
  if (f[len1][len2]) {
    cout << "matched\n";
  } else
    cout << "not matched";
  return 0;
}